package com.mango.wall.dialogs;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.widget.TextView;

import com.mango.config.BaseWall;
import com.mango.request.beans.AdvertBean;
import com.mango.wall.R;

import java.util.Locale;

public class TaskCompleteDialog extends Dialog implements Runnable {
    private final AdvertBean mAdvert;
    private Handler mHandler;

    public TaskCompleteDialog(Context context, AdvertBean advert) {
        super(context, R.style.ManGoWall_Dialog);
        setCanceledOnTouchOutside(false);
        setCancelable(false);

        mAdvert = advert;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mg_wall_dialog_task);

        TextView points = findViewById(R.id.mg_wall_points);
        points.setText(String.format(Locale.getDefault(), "+%d%s", mAdvert
                .adBaseInfo.integral, BaseWall.getInstance().getConfig().comm.integralName));
    }

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        if (hasFocus && mHandler == null) {
            mHandler = new Handler();
            mHandler.postDelayed(this, 1000);
        }
    }

    @Override
    public void run() {
        if (isShowing()) cancel();
    }
}
